/* JavaLog - package tracker 
 * 
 * Copyright (C) 2009 Allyson Lima, Diego Pedro, Victor Freire
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software 
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this 
 * program. If not, see <http://www.gnu.org/licenses/>.
 */
package br.edu.ufcg.ccc.javalog.model;

import java.util.Calendar;

/**
 * Represents a single entry in a package tracker report.
 * 
 * @author Allyson Lima, Diego Pedro, Victor Freire
 * @version 08/11/09
 */
public class ReportEntry {
	private Calendar time;
	private String message;

	/**
	 * Constructs a new report entry with the current time and a report message.
	 * 
	 * @param message
	 *            message
	 * @throws IllegalArgumentException
	 *             thrown when an invalid message is passed
	 */
	public ReportEntry(String message) throws IllegalArgumentException {
		this(Calendar.getInstance(), message);
	}

	/**
	 * Constructs a new report entry with an associated time and a report
	 * message.
	 * 
	 * @param time
	 *            time associated with this entry
	 * @param message
	 *            message
	 */
	public ReportEntry(Calendar time, String message) {
		Validator.validateObject(time,
				new IllegalArgumentException("Calendário inválido."));
		Validator.validatePhrase(message, new IllegalArgumentException(
				"message failed validation"));
		this.time = time;
		this.message = message;
	}

	/**
	 * Returns the time associated with this message.
	 */
	public Calendar getTime() {
		return this.time;
	}

	/**
	 * Returns this entry's message.
	 */
	public String getMessage() {
		return this.message;
	}

	/**
	 * Sets a new time.
	 * 
	 * @param calendar
	 *            new time
	 * @throws IllegalArgumentException
	 *             thrown when an invalid calendar is passed
	 */
	public void setTime(Calendar calendar) throws IllegalArgumentException {
		Validator.validateObject(calendar, new IllegalArgumentException(
				"Calendário inválido."));
		this.time = calendar;
	}

	/**
	 * Sets a new message.
	 * 
	 * @param message
	 *            new message
	 * @throws IllegalArgumentException
	 *             thrown when an invalid message is passed
	 */
	public void setMessage(String message) throws IllegalArgumentException {
		Validator.validatePhrase(message, new IllegalArgumentException(
				"message validation failed"));
		this.message = message;
	}
	/**
	 * Describes the ReportEntry
	 * 
	 * @return description of the ReportEntry
	 */
	@Override
	public String toString(){
		//TODO translate time to portuguese
		return String.format("Horario de expedimento: %s%nRelatório: %s%n",
				time.getTime(),message);
	}

}
